package com.yix.study.tec.entity;

import javax.swing.*;
import java.awt.*;

/**
 * 原型模式
 */
public class ProtoTypeWukong{
    public static void main(String[] args) {
        JFrame jFrame = new JFrame("原型模式测试");
        jFrame.setLayout(new GridLayout(1,2));
        Container container = jFrame.getContentPane();
        SunWuKong sunWuKong = new SunWuKong();
        container.add(sunWuKong);
        SunWuKong sunWuKong1 = (SunWuKong) sunWuKong.clone();
        container.add(sunWuKong1);
        jFrame.pack();
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

class SunWuKong extends JPanel implements Cloneable {

    private static final long serialVersionUID = -6379095131331482344L;

    public SunWuKong(){
        JLabel jLabel = new JLabel(new ImageIcon(System.getProperty("user.dir")+"\\src\\main\\resources\\static\\WuKong.jpg"));
        this.add(jLabel);
    }

    @Override
    protected Object clone()  {
        SunWuKong w = null;
        try {
            w = (SunWuKong) super.clone();
        } catch (CloneNotSupportedException e) {
            System.out.println("拷贝悟空失败!");
        }
        return w;
    }
}
